import CryptoJS from 'crypto-js';

const key = 'kw18sjfy382bif9s'; // 秘钥

export const encrypt = (word: string) => {
  const keyUtf8 = CryptoJS.enc.Utf8.parse(key);
  const bytes = CryptoJS.AES.encrypt(word, keyUtf8, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7,
  });
  return bytes.toString();
};

export const decrypt = (word: string) => {
  const keyUtf8 = CryptoJS.enc.Utf8.parse(key);
  const bytes = CryptoJS.AES.decrypt(word, keyUtf8, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7,
  });
  return CryptoJS.enc.Utf8.stringify(bytes).toString();
};
